﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Vds2465Telegrams
{
    [TestClass]
    public class UserData_10_Query_Test
    {
        [TestMethod]
        [Owner("Frank Eppink")]
        public void Test00_Constructor()
        {
            UserData_10_Query userDataState = new UserData_10_Query(UserData.UserData20State, 0x32, 0x11, 0x22, 0x33);
            
            UserData_10_Query userDataTestTimer = new UserData_10_Query(UserData.UserData41TestConfirm, 0x32, 0x11, 0x22, 0x33);
        }

        [TestMethod]
        [Owner("Frank Eppink")]
        public void Test01_Equals_Simple()
        {
            UserData_10_Query userData = new UserData_10_Query(UserData.UserData01Priority, 0x32);

            {
                // completely different type - NOT equal
                object dummyObject = new object();
                Assert.IsFalse(userData.Equals(dummyObject));
            }

            {
                // different variant
                UserData_10_Query userData2Compare = new UserData_10_Query(userData.QueryType, userData.Device, 0x11, 0x22, 0x55);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // compare with variant with the same 2 properties
                UserData_10_Query userData2Compare = new UserData_10_Query(userData.QueryType, userData.Device);
                Assert.IsTrue(userData.Equals(userData2Compare));
            }

            {
                // different queryType
                UserData_10_Query userData2Compare = new UserData_10_Query((byte) (userData.QueryType + 1), userData.Device);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // different device
                UserData_10_Query userData2Compare = new UserData_10_Query(userData.QueryType, (byte)(userData.Device + 1));
                Assert.IsFalse(userData.Equals(userData2Compare));
            }
        }

        [TestMethod]
        [Owner("Frank Eppink")]
        public void Test02_Equals_General()
        {
            UserData_10_Query userData = new UserData_10_Query(0x55, 0x32, 0x11, 0x22, 0x55);

            {
                // completely different type - NOT equal
                object dummyObject = new object();
                Assert.IsFalse(userData.Equals(dummyObject));
            }

            {
                // different variant
                UserData_10_Query userData2Compare = new UserData_10_Query(userData.QueryType, userData.Device);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // compare with variant with the same properties
                UserData_10_Query userData2Compare = new UserData_10_Query(userData.QueryType, userData.Device, userData.Address, userData.AddressAddOn, userData.AddressExtension);
                Assert.IsTrue(userData.Equals(userData2Compare));
            }

            {
                // different queryType
                UserData_10_Query userData2Compare = new UserData_10_Query((byte)(userData.QueryType + 1), userData.Device, userData.Address, userData.AddressAddOn, userData.AddressExtension);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // different device
                UserData_10_Query userData2Compare = new UserData_10_Query(userData.QueryType, (byte)(userData.Device + 1), userData.Address, userData.AddressAddOn, userData.AddressExtension);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // different address
                UserData_10_Query userData2Compare = new UserData_10_Query(userData.QueryType, userData.Device, (byte)(userData.Address + 1), userData.AddressAddOn, userData.AddressExtension);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // different addressAddOn
                UserData_10_Query userData2Compare = new UserData_10_Query(userData.QueryType, userData.Device, userData.Address, (byte)(userData.AddressAddOn + 1), userData.AddressExtension);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // different addressExtension
                UserData_10_Query userData2Compare = new UserData_10_Query(userData.QueryType, userData.Device, userData.Address, userData.AddressAddOn, (byte)(userData.AddressExtension + 1));
                Assert.IsFalse(userData.Equals(userData2Compare));
            }
        }

        [TestMethod]
        [Owner("Frank Eppink")]
        public void Test03_Equals_State()
        {
            UserData_10_Query userData = new UserData_10_Query(UserData.UserData24BlockState, 0x32, 0x11, 0x22, (byte)eAddressExtension_1.Input);

            {
                // completely different type - NOT equal
                object dummyObject = new object();
                Assert.IsFalse(userData.Equals(dummyObject));
            }

            {
                // different variant
                UserData_10_Query userData2Compare = new UserData_10_Query(userData.QueryType, userData.Device);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // compare with variant with the same properties
                UserData_10_Query userData2Compare = new UserData_10_Query(userData.QueryType, userData.Device, userData.Address, userData.AddressAddOn, userData.AddressExtension);
                Assert.IsTrue(userData.Equals(userData2Compare));
            }

            {
                // different queryType
                UserData_10_Query userData2Compare = new UserData_10_Query(UserData.UserData20State, userData.Device, userData.Address, userData.AddressAddOn, userData.AddressExtension);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // different device
                UserData_10_Query userData2Compare = new UserData_10_Query(userData.QueryType, (byte)(userData.Device + 1), userData.Address, userData.AddressAddOn, userData.AddressExtension);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // different address
                UserData_10_Query userData2Compare = new UserData_10_Query(userData.QueryType, userData.Device, (byte)(userData.Address + 1), userData.AddressAddOn, userData.AddressExtension);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // different addressAddOn
                UserData_10_Query userData2Compare = new UserData_10_Query(userData.QueryType, userData.Device, userData.Address, (byte)(userData.AddressAddOn + 1), userData.AddressExtension);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // different addressExtension
                UserData_10_Query userData2Compare = new UserData_10_Query(userData.QueryType, userData.Device, userData.Address, userData.AddressAddOn, (byte)(userData.AddressExtension + 1));
                Assert.IsFalse(userData.Equals(userData2Compare));
            }
        }

        [TestMethod]
        [Owner("Frank Eppink")]
        public void Test04_Equals_TestTimer()
        {
            UserData_10_Query userData = new UserData_10_Query(UserData.UserData41TestConfirm, 0x32, 0x11, 0x22, (byte)eAddressExtension_2.TestMessageInterval);

            {
                // completely different type - NOT equal
                object dummyObject = new object();
                Assert.IsFalse(userData.Equals(dummyObject));
            }

            {
                // different variant
                UserData_10_Query userData2Compare = new UserData_10_Query(userData.QueryType, userData.Device);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // compare with variant with the same properties
                UserData_10_Query userData2Compare = new UserData_10_Query(userData.QueryType, userData.Device, userData.Address, userData.AddressAddOn, userData.AddressExtension);
                Assert.IsTrue(userData.Equals(userData2Compare));
            }

            {
                // different queryType
                UserData_10_Query userData2Compare = new UserData_10_Query(UserData.UserData20State, userData.Device, userData.Address, userData.AddressAddOn, userData.AddressExtension);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // different device
                UserData_10_Query userData2Compare = new UserData_10_Query(userData.QueryType, (byte)(userData.Device + 1), userData.Address, userData.AddressAddOn, userData.AddressExtension);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // different address
                UserData_10_Query userData2Compare = new UserData_10_Query(userData.QueryType, userData.Device, (byte)(userData.Address + 1), userData.AddressAddOn, userData.AddressExtension);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // different addressAddOn
                UserData_10_Query userData2Compare = new UserData_10_Query(userData.QueryType, userData.Device, userData.Address, (byte)(userData.AddressAddOn + 1), userData.AddressExtension);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // different addressExtension
                UserData_10_Query userData2Compare = new UserData_10_Query(userData.QueryType, userData.Device, userData.Address, userData.AddressAddOn, (byte)(userData.AddressExtension + 1));
                Assert.IsFalse(userData.Equals(userData2Compare));
            }
        }

        [TestMethod]
        [Owner("Frank Eppink")]
        public void Test03_GetHashCode()
        {
            {
                // simple
                UserData_10_Query userData = new UserData_10_Query(UserData.UserData01Priority, 0x32);
                int hashCode = userData.GetHashCode();
            }

            {
                // general
                UserData_10_Query userData = new UserData_10_Query(0x55, 0x32, 0x11, 0x22, 0x55);
                int hashCode = userData.GetHashCode();
            }


            {
                // query state
                UserData_10_Query userData = new UserData_10_Query(UserData.UserData41TestConfirm, 0x32, 0x11, 0x22, (byte)eAddressExtension_2.TestMessageInterval);
                int hashCode = userData.GetHashCode();
            }

            {
                // test timer
                UserData_10_Query userData = new UserData_10_Query(UserData.UserData41TestConfirm, 0x32, 0x11, 0x22, (byte)eAddressExtension_2.TestMessageInterval);
                int hashCode = userData.GetHashCode();
            }
        }

        [TestMethod]
        [Owner("Frank Eppink")]
        public void Test04_ToString()
        {
            {
                // simple
                UserData_10_Query userData = new UserData_10_Query(UserData.UserData01Priority, 0x32);
                string stringResult = userData.ToString();
                Assert.IsNotNull(stringResult);
            }

            {
                // general
                UserData_10_Query userData = new UserData_10_Query(0x55, 0x32, 0x11, 0x22, 0x55);
                string stringResult = userData.ToString();
                Assert.IsNotNull(stringResult);
            }

            {
                // query state
                UserData_10_Query userData = new UserData_10_Query(UserData.UserData24BlockState, 0x32, 0x11, 0x22, (byte)eAddressExtension_1.Disruption);
                string stringResult = userData.ToString();
                Assert.IsNotNull(stringResult);
            }

            {
                // test timer
                UserData_10_Query userData = new UserData_10_Query(UserData.UserData41TestConfirm, 0x32, 0x11, 0x22, (byte)eAddressExtension_2.TestMessageInterval);
                string stringResult = userData.ToString();
                Assert.IsNotNull(stringResult);
            }
        }
    }
}
